<?php
//组成多维数组
//unction nodeForLayer($node, $pid = 0) {
//$access是从数据库读出来的权限数据数组
function nodeForLayer($node, $access = null, $pid = 0) {
	
	if($node == '') return array();
	$arr = array();

	foreach ($node as $v) {
		if (is_array($access)) {
			
			$v['access'] =in_array($v['id'], $access)? 1 : 0;
		}
		if ($v['pid'] == $pid) {
			$v['child'] = nodeForLayer($node, $access, $v['id']);
			$arr[] =$v;
		}
	}

	return $arr;
}

//返回
function flag2Str($flag, $delimiter=' ', $iskey = false, $isarray = false) {
	if (empty($flag)) {
		return $isarray? array(): '';
	}
	$flagStr = array();
	$flagtype = getArrayOfItem('flagtype');//文档属性
	foreach ($flagtype as $k => $v) {
		if ($flag & $k) {
			$flagStr[] = $iskey? $k : $v;
		}
	}
	if ($isarray) {
		return $flagStr;
	} else {
		return implode($delimiter, $flagStr);
	}

}

//数组按key拷贝
function cloneByKey(&$oldarr, &$newarr) {
    foreach ($oldarr as $key => $value) {
        $newarr[$key] = $value;
    }
}

//生成人才详情页url
function genTalentURL($user){
    $url = "";
    $resUser = M('user_info')->where('uid='.$user)->find();
    if ($resUser['utype']==1) {
        $url = 'http://'.getDomain().'/talent'.$user.'.html';
    }
    else if($user['utype']==2){
        
    }
    return $url;
}
//生成职位详情页url
function genJobURL($job) {
    return 'http://'.getDomain().'/job'.$job.'.html';
}

//保留小数点1位
function onebit($num) {
    return floor($num*10)/10;
}
//用户评分星级转十分制
function rate2score($rate) {
    return floor($rate)+ceil($rate);
}
//用户评分十分制转星级
function score2rate($score) {
    return $score-($score%2)*0.5-floor($score/2);
}

//由用户间的评分得到描述等级
function rate2C($rate) {
    $c = '';
    if (0<$rate && $rate<7) {
        $c = "一般";
    }
    else if (7<=$rate && $rate<10) {
        $c = "良好";
    }
    else if ($rate==10) {
        $c = "满意";
    }
    return $c;
}

?>